//
//  ScanFiles.swift
//  Scaner
//
//  Created by liyahao on 2025/4/14.
//

import UIKit
import SQLite

struct ScanFiles: Identifiable {
    var id: Int
    var name: String
    var path: String
    var page: Int
    var tsp: String // 时间戳
    var ocr: String? // ocr识别文字
    var lat: String? // 纬度
    var lng: String? // 经度
    var location: String? // 地点名称
}

extension ScanFiles: SQLProtocol {
    static var table = SQLite.Table("audio")
    
    // 创建数据库
    static var tableCreate: String {
        let intKeys: [String] = ["page"]
        let strKeys: [String] = ["name","path","tsp"]
        let optKeys: [String] = ["ocr","location","lat","lng"]
        return Self.table.create(ifNotExists: true) { table in
            table.column(SQLite.Expression<Int64>("id"), primaryKey: true)
            intKeys.forEach { table.column(SQLite.Expression<Int>($0)) }
            strKeys.forEach { table.column(SQLite.Expression<String>($0)) }
            optKeys.forEach { table.column(SQLite.Expression<String?>($0)) }
        }
    }
}
